import Vue from 'vue';
import ErrorComp from './error';

const ErrorConstructor = Vue.extend(ErrorComp);

const error = (options) => {
  // eslint-disable-next-line
  console.log(options);
  if (Vue.prototype.$isServer) return;
  const instance = new ErrorConstructor({
    propsData: {
      message: options.ms,
    },
  });
  instance.vm = instance.$mount();
  instance.vm.$on('close', () => {
    document.body.removeChild(instance.vm.$el);
    instance.vm.$destroy();
  });
  document.body.appendChild(instance.vm.$el);
};

export default error;
